package cn.seqdata.javatime;

import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;

public class ConvertUtils {

	public static <T, R> R nullSafe(T value, Function<T, R> mapper) {
		return Objects.nonNull(value) ? mapper.apply(value) : null;
	}

	public static <T, R> R nullSafe(T value, Function<T, R> mapper, R defaultValue) {
		return Objects.nonNull(value) ? mapper.apply(value) : defaultValue;
	}

	public static <T, R> R nullSafe(T value, Function<T, R> mapper, Supplier<R> defaultSupplier) {
		return Objects.nonNull(value) ? mapper.apply(value) : defaultSupplier.get();
	}
}
